package com.atguigu.gulimaill.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;


@Data
public class CartVo {
    private List<CartItemVo> cartItems;
    private BigDecimal reduce = new BigDecimal(0);

    public Integer getCountNum() {
        Integer countNum = 0;
        if (cartItems != null && !cartItems.isEmpty()) {
            for (CartItemVo cartItem : cartItems) {
                countNum += cartItem.getCount();
            }
            return countNum;
        } else {
            return 0;
        }
    }


    public Integer getCountType() {
        if (cartItems != null && !cartItems.isEmpty()) {
            return cartItems.size();
        } else {
            return 0;
        }
    }


    public BigDecimal getTotalAmount() {
        BigDecimal totalAmount = new BigDecimal(0);
        if (cartItems != null && !cartItems.isEmpty()) {
            for (CartItemVo cartItem : cartItems) {
                totalAmount = totalAmount.add(cartItem.getTotalPrice());
            }
            totalAmount = totalAmount.subtract(reduce);
        }
        return totalAmount;
    }


}
